#!/bin/bash

###SHELLPACK preamble stressng-bench 0

STRESSNG_MIN_THREADS=1
STRESSNG_MAX_THREADS=1
STRESSNG_RUNTIME=150
STRESSNG_ITERATIONS=3
STRESSNG_TESTNAME=context

###SHELLPACK parseargBegin
###SHELLPACK parseargInstall
###SHELLPACK parseargParam    --min-threads STRESSNG_MIN_THREADS
###SHELLPACK parseargParam    --max-threads STRESSNG_MAX_THREADS
###SHELLPACK parseargParam    --runtime     STRESSNG_RUNTIME
###SHELLPACK parseargParam    --iterations  STRESSNG_ITERATIONS
###SHELLPACK parseargParam    --testname    STRESSNG_TESTNAME
###SHELLPACK parseargEnd
###SHELLPACK monitor_hooks

###SHELLPACK check_install_required stressng-${VERSION}
###SHELLPACK init_complete

TESTSWITCH=
case $STRESSNG_TESTNAME in
get)
	TESTSWITCH="--get"
	;;
context)
	TESTSWITCH="--context"
	;;
io-class)
	TESTSWITCH="--class io"
	;;
io-class-parallel)
	TESTSWITCH="--class io --all 1"
	;;
*)
	die "Unrecognised test $STRESSNG_TESTNAME"
	;;
esac

###SHELLPACK threads_powertwo_begin $STRESSNG_MIN_THREADS $STRESSNG_MAX_THREADS
	mmtests_activity $NR_THREADS
	monitor_pre_hook $LOGDIR_RESULTS $NR_THREADS

	###SHELLPACK iteration_begin $STRESSNG_ITERATIONS
		echo Running $NR_THREADS stressng $STRESSNG_TESTNAME iteration $ITERATION
		$TIME_CMD -o $LOGDIR_RESULTS/time-$NR_THREADS-$ITERATION \
			./stress-ng $TESTSWITCH $NR_THREADS \
				--timeout ${STRESSNG_RUNTIME}s \
				--metrics-brief 2>&1 |\
				tee $LOGDIR_RESULTS/stressng-$NR_THREADS-$ITERATION.log
	###SHELLPACK iteration_end $STRESSNG_ITERATIONS

	monitor_post_hook $LOGDIR_RESULTS $NR_THREADS
###SHELLPACK threads_powertwo_end

exit $SHELLPACK_SUCCESS
